<?php

function vd($var, $exit = 1)
{
    echo '<pre>';
    var_dump($var);
    echo '</pre>';
    
    if ($exit)
    {
        exit;
    }
}

function error($code, $text, $startTime = false, $superCode = false)
{
	$array = array();
	$array['response'] = 'error';
	$array['code']     = $code;
	$array['message']  = $text;
        
        if ($startTime)
        {
            $array['timeRequest'] = resTimeScript($startTime);
        }
        
        if ($superCode)
        {
            $array['super_code'] = $superCode;
        }
        
	return $array;
}

function storeLog($nameFile, $textFile)
{
    $file = fopen('./log/'.$nameFile.'.log', "a+");
    
    if (is_resource($file))
    {
            fwrite($file, $textFile);
            fclose($file);
            return TRUE;
    }
    return FALSE;
}

function startTimeScript()
{
    return microtime(true);
}

function resTimeScript($startTime)
{
    $finishTime = microtime(true);
    $totalTime = $finishTime - $startTime;
    return  'Время выполнения запроса: ' . round($totalTime, 6) . ' секунд';
}

?>
